package com.cs.study.homework._0221;

public class Demo1 {
    public static void main(String[] args) {
        //访问机制测试
        Son1 son = new Son1();
        son.test();
        son.test2();
        System.out.println(son.a);
        Father1 son1 = new Son1();
        son1.test();
        son1.test2();
        System.out.println(son1.a);
        Father1 father = new Father1();
        father.test();
        father.test2();
        System.out.println(father.a);

    }
}

class Father1 {
    int a = 1;

    public void test() {
        System.out.println("father test");
    }

    public void test2() {
        System.out.println("father test2");
    }
    public Father1 test3(){
        System.out.println("father test3");
        return null;
    }

}

class Son1 extends Father1 {
    int a = 2;

    //方法覆盖/重写
    @Override
    public void test() {
        System.out.println("son test");
    }

    @Override
    public Father1 test3() {
        System.out.println("son test3");
        return new Son1();
    }
}
